﻿using System;
using System.Collections.Generic;

using DataFactory.Config;
using IDAL.Config;
using Model.Config;
namespace BLL.Config
{
    /// <summary>
    /// 业务层，网站配置，术语表
    /// </summary>
    public class TermBLL
    {
        /// <summary>
        /// 私有术语对象
        /// </summary>
        private ITerm dal = DataAccess.CreateTerm();
        
        /// <summary>
        /// 新增术语
        /// </summary>
        /// <param name="info">术语对象</param>
        /// <param name="message">返回操作信息提示</param>
        /// <returns></returns>
        public int InsertTerm(TermInfo info, out string message)
        {
            return dal.InsertTerm(info, out message);
        }

        /// <summary>
        /// 修改术语
        /// </summary>
        /// <param name="info">术语对象</param>
        /// <param name="message">返回操作信息提示</param>
        /// <returns></returns>
        public bool UpdateTerm(TermInfo info, out string message)
        {
            return dal.UpdateTerm(info, out message);
        }
        /// <summary>
        /// 获取术语
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TermInfo GetTermByID(int id)
        {
            return dal.GetTermByID(id);
        }

        /// <summary>
        /// 根据父级编号获取术语列表
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public IList<TermInfo> ListTermByParentID(int parent)
        {
            TermCondition condition = new TermCondition();
            condition.ParentTermID = parent;
            condition.OrderBy = "AddTime DESC";
            return dal.ListTerm(condition);
        }

        /// <summary>
        /// 根据父级标签获取术语列表
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>
        public IList<TermInfo> ListTermByParentLabel(string label)
        {
            TermCondition condition = new TermCondition();
            condition.ParentTermID = -1;
            condition.ParentTermLabel = label;            
            condition.OrderBy = "AddTime DESC";
            return dal.ListTerm(condition);
        }

        /// <summary>
        /// 后台术语列表
        /// </summary>
        /// <param name="parentID"></param>
        /// <param name="parentLabel"></param>
        /// <param name="keyWord"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public IList<TermInfo> BackList(int parentID, string parentLabel, string keyWord, int pageIndex, int pageSize, out int recordCount) 
        {
            TermCondition condition = new TermCondition();
            condition.ParentTermID = parentID;
            condition.ParentTermLabel = parentLabel;
            condition.PageIndex = pageIndex;
            condition.PageSize = pageSize;
            condition.OrderBy = "AddTime ASC";
            return dal.ListTerm(condition, out recordCount);
        }
    }
}
